<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@1.11.1/dist/jquery.min.js"></script>

</head>
<body>
<h2>登录页面</h2>
<h3>社交登录</h3>
<a href="#" onclick="auth2('/demo/auth2/authorization/gitee')">gitee登录ajax</a>
<a href="/demo/auth2/authorization/gitee">gitee登录</a>
<a href="#" onclick="auth2('/demo/auth2/authorization/giteeCustomize')">自定义OAuth2登录ajax</a>
<a href="/demo/auth2/authorization/giteeCustomize">自定义OAuth2登录</a>

<!-- 示例未实现, 有私有 GitLab 仓库可以自己实现
<a href="#" onclick="auth2('/demo/auth2/authorization/gitlabPrivate')">GitlabPrivate登录ajax</a>
<a href="/demo/auth2/authorization/gitlabPrivate">GitlabPrivate登录</a>-->

<a href="/demo/auth2/authorization/github">github登录</a>
<a href="/demo/auth2/authorization/qq">qq登录</a>
<br><br>
<a th:href="@{/index.html}">首页</a>
</body>

<script>
    auth2 = function (url) {
        $.ajax({
            // 如果用的是模板，则 url 可以使用注入的方式，会跟着配置动态改变
            url: url,
            type: "GET",
            dataType: "json",
            contentType: 'application/json; charset=UTF-8',
            success: function (data) {
                console.log("获取的第三方授权 status = " + data.status)
                console.log("获取的第三方授权 url = " + data.url)
                //...
                if (data.status === 302) {
                    window.location.href = data.url;
                }
            },
            error: function (data) {
                // 登录失败
                console.log("********登录失败*********")
                console.log(data)
            }
        })
    }
</script>
</html>